package com.codinglives.demoall.mulds.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class DruidDataSource2Config {


    @Autowired
    @Qualifier("cp2")
    private ConnectionProperties2 connectionProperties;

    @Bean("dataSource2")
    public DataSource initDataSource1() {
        DruidDataSource dataSource = new DruidDataSource();
        try {
            dataSource.setUrl(connectionProperties.getUrl());
            dataSource.setDriverClassName(connectionProperties.getDriverClassName());
            dataSource.setUsername(connectionProperties.getUsername());
            dataSource.setPassword(connectionProperties.getPassword());
            dataSource.setInitialSize(connectionProperties.getInitialSize());
            dataSource.setMinIdle(connectionProperties.getMinIdle());
            dataSource.setMaxWait(connectionProperties.getMaxWait());
            dataSource.setMaxActive(connectionProperties.getMaxActive());
            dataSource.setMinEvictableIdleTimeMillis(connectionProperties.getMinEvictTime());
            dataSource.setFilters("stat,wall,slf4j,default");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dataSource;
    }

}
